package com.ruoyi.web.controller.oms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oms.entity.OrderCompensate;
import com.ruoyi.oms.service.IOrderCompensateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 退款退货订单Controller
 *
 * @author ruoyi
 * @date 2021-11-02
 */
@RestController
@RequestMapping("/oms/compensate")
public class OmsOrderCompensateController extends BaseController {
    @Autowired
    private IOrderCompensateService omsOrderCompensateService;

    /**
     * 查询退款退货订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:compensate:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderCompensate omsOrderCompensate) {
        startPage();
        List<OrderCompensate> list = omsOrderCompensateService.list(new QueryWrapper<>(omsOrderCompensate));
        return getDataTable(list);
    }

    /**
     * 导出退款退货订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:compensate:export')")
    @Log(title = "退款退货订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderCompensate omsOrderCompensate) {
        List<OrderCompensate> list = omsOrderCompensateService.list(new QueryWrapper<>(omsOrderCompensate));
        ExcelUtil<OrderCompensate> util = new ExcelUtil<OrderCompensate>(OrderCompensate.class);
        return util.exportExcel(list, "退款退货订单数据");
    }

    /**
     * 获取退款退货订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:compensate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(omsOrderCompensateService.getById(id));
    }

    /**
     * 新增退款退货订单
     */
    @PreAuthorize("@ss.hasPermi('system:compensate:add')")
    @Log(title = "退款退货订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderCompensate omsOrderCompensate) {
        return toAjax(omsOrderCompensateService.save(omsOrderCompensate));
    }

    /**
     * 修改退款退货订单
     */
    @PreAuthorize("@ss.hasPermi('system:compensate:edit')")
    @Log(title = "退款退货订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderCompensate omsOrderCompensate) {
        return toAjax(omsOrderCompensateService.updateById(omsOrderCompensate));
    }

    /**
     * 删除退款退货订单
     */
    @PreAuthorize("@ss.hasPermi('system:compensate:remove')")
    @Log(title = "退款退货订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        List<Long> list = Arrays.asList(ids);
        return toAjax(omsOrderCompensateService.removeByIds(list));
    }
}